package patterns.dao;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2016/12/12 0012.
 */
public class StudentDaoImple implements IStudentDao {
    //列表模拟作为数据库
    List<Student> students;

    public StudentDaoImple() {
        students = new ArrayList<>();
        Student s1 = new Student("robert",0);
        Student s2 = new Student("john",1);
        students.add(s1);
        students.add(s2);
    }

    @Override
    public List<Student> getAllStudents() {
        return students;
    }

    @Override
    public Student getStudent(int rollNo) {
        return students.get(rollNo);
    }

    @Override
    public void updateStudent(Student student) {
        students.get(student.getRollNo()).setName(student.getName());
        System.out.println("更新了一个数据："+student.getRollNo());
    }

    @Override
    public void deleteStudent(Student student) {
        students.remove(student.getRollNo());
        System.out.println("清理掉了一个用户数据："+student.getName());
    }
}
